package com.liang.beikebusinesshandler.core.domain;

import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author liangyehao
 * @version 1.0
 * @date 2021/4/24 17:45
 * @content
 */
@Data
public class ResponseData {

    @ExcelProperty(value = "门店",index = 0)
    private String store;

    @ExcelProperty("唯一会话量")
    private Integer sessionAmount;
    @ExcelProperty("录入量")
    private Integer inputAmount;
    @ExcelProperty("录入率")
    private BigDecimal inputRate;
    @ExcelProperty("带看量")
    private Integer takeLookAtAmount;
    @ExcelProperty("会话转带看率")
    private BigDecimal takeLookAtRate;

    @ExcelProperty({"买卖","唯一会话量"})
    private Integer bsSessionAmount;
    @ExcelProperty({"买卖","录入量"})
    private Integer bsInputAmount;
    @ExcelProperty({"买卖","录入率"})
    private BigDecimal bsInputRate;
    @ExcelProperty({"买卖","带看量"})
    private Integer bsTakeLookAtAmount;
    @ExcelProperty({"买卖","会话转带看率"})
    private BigDecimal bsTakeLookAtRate;

    @ExcelProperty({"租赁","唯一会话量"})
    private Integer rentSessionAmount;
    @ExcelProperty({"租赁","录入量"})
    private Integer rentInputAmount;
    @ExcelProperty({"租赁","录入率"})
    private BigDecimal rentInputRate;
    @ExcelProperty({"租赁","带看量"})
    private Integer rentTakeLookAtAmount;
    @ExcelProperty({"租赁","会话转带看率"})
    private BigDecimal rentTakeLookAtRate;

    @ExcelProperty({"新房","唯一会话量"})
    private Integer newSessionAmount;
    @ExcelProperty({"新房","录入量"})
    private Integer newInputAmount;
    @ExcelProperty({"新房","录入率"})
    private BigDecimal newInputRate;
    @ExcelProperty({"新房","带看量"})
    private Integer newTakeLookAtAmount;
    @ExcelProperty({"新房","会话转带看率"})
    private BigDecimal newTakeLookAtRate;

    @ExcelProperty({"其他","唯一会话量"})
    private Integer otherSessionAmount;
    @ExcelProperty({"其他","录入量"})
    private Integer otherInputAmount;
    @ExcelProperty({"其他","录入率"})
    private BigDecimal otherInputRate;
    @ExcelProperty({"其他","带看量"})
    private Integer otherTakeLookAtAmount;
    @ExcelProperty({"其他","会话转带看率"})
    private BigDecimal otherTakeLookAtRate;

    @ExcelProperty("已录客未带看")
    private Integer recordButNotWith;
    @ExcelProperty("已录客被他人成交")
    private Integer recordedButDealByOthers;
    @ExcelProperty("未录客被他人录入")
    private Integer unRecordButRecordByOthers;
    @ExcelProperty("未录客被他人带看")
    private Integer unRecordButWithByOthers;
    @ExcelProperty("未录客被他人成交")
    private Integer unRecordButDealByOthers;



    private void setTotal(CommonIndex commonIndex){
        this.sessionAmount = commonIndex.getSessionAmount();
        this.inputAmount = commonIndex.getInputAmount();
        this.inputRate = commonIndex.getInputRate();
        this.takeLookAtAmount = commonIndex.getTakeLookAtAmount();
        this.takeLookAtRate = commonIndex.getTakeLookAtRate();
    }

    private void setBs(CommonIndex commonIndex){
        this.bsSessionAmount = commonIndex.getSessionAmount();
        this.bsInputAmount = commonIndex.getInputAmount();
        this.bsInputRate = commonIndex.getInputRate();
        this.bsTakeLookAtAmount = commonIndex.getTakeLookAtAmount();
        this.bsTakeLookAtRate = commonIndex.getTakeLookAtRate();
    }

    private void setRent(CommonIndex commonIndex){
        this.rentSessionAmount = commonIndex.getSessionAmount();
        this.rentInputAmount = commonIndex.getInputAmount();
        this.rentInputRate = commonIndex.getInputRate();
        this.rentTakeLookAtAmount = commonIndex.getTakeLookAtAmount();
        this.rentTakeLookAtRate = commonIndex.getTakeLookAtRate();
    }

    private void setNew(CommonIndex commonIndex){
        this.newSessionAmount = commonIndex.getSessionAmount();
        this.newInputAmount = commonIndex.getInputAmount();
        this.newInputRate = commonIndex.getInputRate();
        this.newTakeLookAtAmount = commonIndex.getTakeLookAtAmount();
        this.newTakeLookAtRate = commonIndex.getTakeLookAtRate();
    }

    private void setOther(CommonIndex commonIndex){
        this.otherSessionAmount = commonIndex.getSessionAmount();
        this.otherInputAmount = commonIndex.getInputAmount();
        this.otherInputRate = commonIndex.getInputRate();
        this.otherTakeLookAtAmount = commonIndex.getTakeLookAtAmount();
        this.otherTakeLookAtRate = commonIndex.getTakeLookAtRate();
    }


    public void buildStatistics(List<BusinessData> totalData){
        // 总
        this.setTotal(CommonIndex.build(totalData));

        // 买卖
        List<BusinessData> bsData = totalData.stream().filter(data -> "二手房".equals(data.getBusinessTypes())).collect(Collectors.toList());
        this.setBs(CommonIndex.build(bsData));

        // 租赁
        List<BusinessData> rentData = totalData.stream().filter(data -> "租房".equals(data.getBusinessTypes())).collect(Collectors.toList());
        this.setRent(CommonIndex.build(rentData));

        // 新房
        List<BusinessData> newData = totalData.stream().filter(data -> "新房".equals(data.getBusinessTypes())).collect(Collectors.toList());
        this.setNew(CommonIndex.build(newData));

        // 其他
        List<BusinessData> otherData = totalData.stream().filter(data -> "未知".equals(data.getBusinessTypes())).collect(Collectors.toList());
        this.setOther(CommonIndex.build(otherData));

    }

    public void buildLost(List<BusinessData> totalData, LostData lostData) {
        List<BusinessData> unRecordData = totalData.stream().filter(data -> "未录入".equals(data.getRecordGuestIs())).collect(Collectors.toList());
        List<BusinessData> recordedData = totalData.stream().filter(data -> "商机后录入".equals(data.getRecordGuestIs())).collect(Collectors.toList());

        List<BusinessData> unRecordButRecordByOthersData = unRecordData.stream().filter(data -> "是".equals(data.getWhetherOthersInput())).collect(Collectors.toList());
        List<BusinessData> unRecordButWithByOthersData = unRecordData.stream().filter(data -> "是".equals(data.getWhetherOtherPeopleSee())).collect(Collectors.toList());
        List<BusinessData> unRecordButDealByOthersData = unRecordData.stream().filter(data -> "是".equals(data.getWhetherOthersClinchADeal())).collect(Collectors.toList());
        List<BusinessData> recordedButDealByOthersData = recordedData.stream().filter(data -> "是".equals(data.getWhetherOthersClinchADeal())).collect(Collectors.toList());
        List<BusinessData> recordButNotWithData = recordedData.stream().filter(data -> "0".equals(data.getQuantity())).collect(Collectors.toList());

        this.unRecordButRecordByOthers = unRecordButRecordByOthersData.size();
        this.unRecordButWithByOthers = unRecordButWithByOthersData.size();
        this.unRecordButDealByOthers = unRecordButDealByOthersData.size();
        this.recordedButDealByOthers = recordedButDealByOthersData.size();
        this.recordButNotWith = recordButNotWithData.size();

        if (lostData!=null) {
            lostData.getUnRecordButRecordByOthersList().addAll(unRecordButRecordByOthersData);
            lostData.getUnRecordButWithByOthersList().addAll(unRecordButWithByOthersData);
            lostData.getUnRecordButDealByOthersList().addAll(unRecordButDealByOthersData);
            lostData.getRecordedButDealByOthersList().addAll(recordedButDealByOthersData);
            lostData.getRecordButNotWithList().addAll(recordButNotWithData);
        }

    }


}
